package cn.rubintry.weacar.autodingtalk

import android.content.Intent
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity() {
    override fun layout(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        tv_main.text = "ssf"
    }


    override fun onStart() {
        super.onStart()
        //打开钉钉
        startTimeService(13, 28)
//        startTimeService(13, 25)

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            if (!BatteryIgnoreUtils.isIgnoringBatteryOptimizations()) {
                BatteryIgnoreUtils.requestIgnoreBatteryOptimizations()
            }
        }
    }


    /**
     * 开启一个定时任务
     */
    fun startTimeService(hours: Int, minutes: Int) {
        val intent = Intent(this, AutoService::class.java)
        intent.putExtra("hour", hours)
        intent.putExtra("minute", minutes)
//        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
//            startForegroundService(intent)
//        } else {
            startService(intent)
//        }
    }

}